/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OpretLeverandor.java
 *
 * Created on Dec 6, 2011, 11:45:18 AM
 */
package GUILayer;
import ControlLayer.CtrSupplier;
import ModelLayer.Supplier;
import ControlLayer.CtrProduct;

/**
 *
 * @author R3l4X
 */
public class OpretLeverandor extends javax.swing.JFrame {
    private CtrProduct ctrProduct;
    private CtrSupplier ctrSupplier;

    /** Creates new form OpretLeverandor */
    public OpretLeverandor() {
        initComponents();
        this.setVisible(true);
        ctrSupplier = new CtrSupplier();
    
  }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel13 = new javax.swing.JLabel();
        txtLeverandorOpretNavn = new javax.swing.JTextField();
        txtLeverandorOpretAdresse = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        txtLeverandorOpretPhone = new javax.swing.JTextField();
        btnLeverandorOpretNy = new javax.swing.JButton();
        btnLeverandorOpretCancel = new javax.swing.JButton();
        lblOpretLeverandor = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Opret Leverandør");

        jLabel13.setText("Navn");

        jLabel14.setText("Adresse");

        jLabel15.setText("Telefon Nummer");

        btnLeverandorOpretNy.setText("Opret");
        btnLeverandorOpretNy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLeverandorOpretNyActionPerformed(evt);
            }
        });

        btnLeverandorOpretCancel.setText("Annuller");
        btnLeverandorOpretCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLeverandorOpretCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblOpretLeverandor)
                    .addComponent(jLabel13)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15)
                            .addComponent(btnLeverandorOpretNy))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnLeverandorOpretCancel)
                            .addComponent(txtLeverandorOpretPhone, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(txtLeverandorOpretNavn)
                                .addComponent(txtLeverandorOpretAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(txtLeverandorOpretNavn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLeverandorOpretAdresse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtLeverandorOpretPhone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addComponent(lblOpretLeverandor)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLeverandorOpretNy)
                    .addComponent(btnLeverandorOpretCancel))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnLeverandorOpretNyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeverandorOpretNyActionPerformed

        try
        {
        CtrSupplier ctrSup = new CtrSupplier();
     
        Supplier supObj = new Supplier();
        
        supObj.setName(txtLeverandorOpretNavn.getText());
        supObj.setAddress(txtLeverandorOpretAdresse.getText());
        supObj.setPhoneNo(Integer.valueOf(txtLeverandorOpretPhone.getText()));
        ctrSup.insertSupplier(supObj);
        
        lblOpretLeverandor.setText("Leverandøren er Oprettet med følgende ID : " + ctrSup.getMaxID());
        }
        
        catch (Exception e)  
        {            
              lblOpretLeverandor.setText("Fejl"); 
        }
        
        
}//GEN-LAST:event_btnLeverandorOpretNyActionPerformed

    private void btnLeverandorOpretCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeverandorOpretCancelActionPerformed

              setVisible(false);
              
    }//GEN-LAST:event_btnLeverandorOpretCancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OpretLeverandor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OpretLeverandor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OpretLeverandor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OpretLeverandor.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new OpretLeverandor().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLeverandorOpretCancel;
    private javax.swing.JButton btnLeverandorOpretNy;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel lblOpretLeverandor;
    private javax.swing.JTextField txtLeverandorOpretAdresse;
    private javax.swing.JTextField txtLeverandorOpretNavn;
    private javax.swing.JTextField txtLeverandorOpretPhone;
    // End of variables declaration//GEN-END:variables
}
